<?php

/*
 * Controller Chi tiet ho so
 */
?>
<?php

class ChitietController extends UngvienTiisController {

    //index controller
    public function actionIndex() {
        
        //import js & css
        Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/hoso.css');
        Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/jquery-1.7.1.min.js', CClientScript::POS_HEAD);
        Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/bootbox.min.js', CClientScript::POS_HEAD);
        
        //id ho so
        $hid = $_GET['id'] > 0 ? $_GET['id'] : 0;
        $hoso = Hoso::model()->with('luong','bangcap')->findByPk($hid);
        

        //id user login
        $uid = Yii::app()->user->getState('info_ungvien')->id;

        if ($hoso) {

            //kiem tra ho so & ung vien
            $hoso_nguoitimviec = Hoso_Nguoitimviec::model()->find('nguoitimviec_id=:uid AND hoso_id=:hid ', array(':uid' => $uid, ':hid' => $hid));
            if ($hoso_nguoitimviec) {

                //thong tin lien he 
                $user = Yii::app()->user->getState('info_ungvien');
                $ngaysinh = $this->convert_date($user->ngaysinh);
                
                //thong tin ho so
                $hoso_luong = HosoLuong::model()->find('hoso_id=:hid', array(':hid' => $hoso->id));
                
                //loai hinh
                $loaihinh = '';
                foreach($hoso->hs_loaihinh as $value)
                    $loaihinh[] = $value->loaihinh->name;
                $loaihinh = implode(', ',$loaihinh);
                
                //chuyen nganh
                $chuyennganh = '';
                foreach($hoso->hs_nganhnghe as $value)
                    $chuyennganh[] = $value->nganhnghe->name;
                $chuyennganh = implode(', ',$chuyennganh);

                //noilamviec
                $noilamviec = '';
                foreach($hoso->hs_thanhpho as $value)
                    $noilamviec[] = $value->thanhpho->name;
                foreach($hoso->hs_quocgia as $value)
                    $noilamviec[] = $value->quocgia->name;
                $noilamviec = implode(', ',$noilamviec);
                
                //qua trinh hoc van
                $quatrinhhoc = Quatrinhhocvan::model()->findAll('hoso_id=:hid', array(':hid' => $hid));
                
                //kinh nghiem lam viec
                $kinhnghiemlamviec = HosoKinhnghiemlamviec::model()->findAll('hoso_id=:hid', array(':hid' => $hid));
                
                //ky nang
                $kynang = HosoKynang::model()->with('kynang')->findAll('hoso_id=:hid', array(':hid' => $hid));
                
                //nguoi tham khao
                $nguoithamkhao = Nguoithamkhao::model()->findAll('hoso_id=:hid', array(':hid' => $hid));
                
                //render file view
                $this->render('form-chitiet',array(
                    'user'          => $user,
                    'ngaysinh'      => $ngaysinh,
                    'hoso'          => $hoso,
                    'hoso_luong'    => $hoso_luong,
                    'loaihinh'      => $loaihinh,
                    'chuyennganh'   => $chuyennganh,
                    'noilamviec'    => $noilamviec,
                    'quatrinhhoc'   => $quatrinhhoc,
                    'knlamviec'     => $kinhnghiemlamviec,
                    'kynang'        => $kynang,
                    'nguoithamkhao' => $nguoithamkhao
                ));
                
            } else {
                $this->redirect(Yii::app()->getBaseUrl(true) . '/ungvien/taohoso.html');
            }
        }else{
            $this->redirect(Yii::app()->getBaseUrl(true) . '/ungvien/taohoso.html');
        }
    }

}

?>